<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="css/lib/bootstrap.min.css" />
		<script src="js/jquery.min.js"></script>
		<script src="js/lib/bootstrap.min.js"></script>
		<script src="js/lib/vue.min.js"></script>
		<script src="js/lib/vue-resource.js"></script>
		<script src="js/base.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<style>
		table,
		/* th,
			td {
				border: 1px solid grey;
				border-collapse: collapse;
				padding: 5px;
				vertical-align: middle !important;
			}	 */	
		/* table td:nth-child(odd) {
			background-color: #ffffff;
			
		} */
		table td:nth-child(even) {
			
		}
		table tr:nth-child(even) {
			background-color:#ffffff;
		}
	</style>
	<body>
		<div class="" id="box" >
		<!-- <div style="padding:15px 5px 0px 5px;border:3px solid #ccc;margin-bottom:15px">
			<table class="table table-hover">				
				<tbody>
					<tr>
						<th colspan="9">三级分销查询：</th>
					</tr>
					<tr>
						<td>品牌编号:</td>
						<td colspan="6">
						<input id="msg0" type="text" class="form-control" style="width:280px;" placeholder="输入品牌编号"/>
						</td>					
					</tr>
					<tr>						
						<td colspan="9">
								<button v-on:click="add()" class="btn btn-danger" style="display:block;margin:0 auto;">点击查询</button>  
						</td>										
					</tr>
					<tr id="title" style="display:none;" class="text-center">
						<td>序号</td>
						<td>产品ID</td>
						<td>品牌编号</td>
						<td>等级</td>
						<td>总金额</td>
						<td>名称</td>
						<td>结算费率</td>
						<td>折扣</td>
						<td>结束时间</td>
					</tr>
					<tr  class="text-center" v-for="(i,index) in list">
						<td>{{index+1}}</td>
						<td>{{i.id}}</td>
						<td>{{i.brandId}}</td>
						<td>{{i.grade}}</td>
						<td>￥{{i.money}}</td>
						<td>{{i.name}}</td>
						<td>{{i.rate}}%</td>
						<td>{{i.discount}}</td>
						<td>{{i.createTime}}</td>
					</tr>
				</tbody>
			</table>		
		</div> -->
		<!--按品牌查询所有三级分销产品返佣比例-->
		<div style="padding:15px 5px 0px 5px;border:3px solid #ccc;margin-bottom:15px">
			<table class="table table-hover">				
				<tbody>
					<tr>
						<th colspan="5" style="font-size:26px;color:#337ab7">修改三级分销产品返佣比例：</th>
					</tr>
					<!-- <tr>
						<td>品牌:</td>
						<td colspan="5">
						<select name="" id="brand_id" v-model="brand_id" type="text" class="form-control" style="width:280px;">
							<option value="">请选择</option>
							<option id="msg1" value=""></option>
						</select>
						</td>					
					</tr> -->
					<!-- <tr>						
						<td colspan="5">
								<button v-on:click="add2()" class="btn btn-danger" style="display:block;margin:0 auto;">点击查询</button>  
						</td>										
					</tr> -->
					<tr id="title1" style="font-size:15px;background:rgb(0, 122, 255);color:#fff" class="text-center">
						<td style="width:80px;">序号</td>
						<!--<td>用户id</td>-->
						<td>品牌编号</td>
						<td>代理级别</td>
						<td>返佣比例</td>
						<td>修改返佣</td>
						<!--<td>结束时间</td>-->
					</tr>
					<tr  class="text-center" v-for="(i,index) in lists">
						<td>{{index+1}}</td>
						<td>{{i.thirdLevelBrandId}}</td>
						<td>{{i.thirdLevelNmae}}</td>
						<td>
							<input type="text" class="form-control ratio" v-model="i.thirdLevelRatio"   style="width:60px;margin:0 auto;">
						</td>
						<td>
							<button v-on:click="up(i)" class="btn btn-default">修改</button>
						</td>
						<!--<td>{{i.createTime}}</td>-->
					</tr>
					<tr>
						<td style="color:red" colspan="5">
							<p>PS:请谨慎设置返佣比例，例如：0.1为返佣10%,最大返佣之和不超过1,最多返3级，每个级别返佣最高0.33</p>
							<p>如若不想把返佣金额返给用户，则需要设置返佣比例全部设置为  0  ；则用户购买产品的费用会全部返给平台（就是您的账号余额里面）</p>
						</td>
					</tr>
				</tbody>
			</table>		
		</div>
		</div>
	</body>
	<script>
		$(function(){
			
			/*自定义过滤器*/
            Vue.filter("todo",function(value){
                if(value == 1){
                    return value = "分销商"
                }
                if(value == 2){
                    return value = "代理商"
                }
                if(value == 3){
                    return value = "服务商"
                }
            });
            /*自定义过滤器2*/
            Vue.filter('todo1',function(value){
                if(value == 1){
                    return value = "赚道钱包"
                }
			});
	new Vue({
				el:"#box",
				data:{
					list:[],
					lists:[],
                    ratio:""
				},
				created:function(){	
					var brandid = sessionStorage.getItem(key=3);
					var brandname = sessionStorage.getItem(key=100);
					console.log(brandname);
					console.log(brandid);
					$('#msg1').val(brandid);
					$('#msg1').text(brandname);
		            var msg1 = $('#msg1').val();			
                    if(msg1 == ""){
                        alert('请输入查询信息！')
                    }else{
                        this.$http.get(window.baseUrl+"user/thirdlevel/prod/ratio/query/"+brandid,{},{emulateJSON:true}).then(
                            function (res) {
                                console.log(res.data.result)
                                this.lists = res.data.result
                                console.log(this.lists)
                                $('#msg1').val("")
                                $('#title1').show()
                            },function (res) {
                                console.log("失败")
                                $('#msg1').val("")
                            }
                        );
                    }
				},
				methods:{
					/*查询三级分销商*/
					add:function(){						
						var msg0 = $('#msg0').val();
						if(msg0 == ""){
							alert("请输入查询信息！")
						}else{
							this.$http.get(window.baseUrl+"user/thirdlevel/prod/brand/"+msg0,{},{emulateJSON:true}).then(
								   function (res) {
								    console.log(res.data)
								    this.list = res.data.result
								    alert(res.data.resp_message)
								    $('#msg0').val("")
								    $('#title').show()
								   },function (res) {
								   	console.log("失败")
								   	 $('#msg0').val("")
								   }
								  );
						}						
					},
					/*查看三级分销比率*/
					add2:function(){
						var msg1 = $('#msg1').val();
						if(msg1 == ""){
							alert('请输入查询信息！')
						}else{
							this.$http.get(window.baseUrl+"user/thirdlevel/ratio/query/"+msg1,{},{emulateJSON:true}).then(
								   function (res) {
								    console.log(res.data.result)
								    this.lists = res.data.result
								    alert(res.data.resp_message);
								    $('#msg1').val("")
								    $('#title1').show()
								   },function (res) {
								   	console.log("失败")
								   	$('#msg1').val("")
								   }
								  );
						}
					},
					up:function(i){/*修改返佣比率*/
					    console.log(i);
					    console.log(i.ratio);
						var brandId = i.thirdLevelBrandId;
						var preLevel = i.thirdLevelGrade;
						var ratio = i.thirdLevelRatio;
                        this.$http.post(window.baseUrl+"user/thirdlevel/ratio/add",{brand_id:brandId,pre_level:preLevel,ratio:ratio},{emulateJSON:true}).then(
                            function (res) {
                            	console.log(res)
                                
                            if(res.data.resp_code == 000000){
                                alert("成功设置三级分销产品返佣比率为"+i.thirdLevelRatio)	
                            }
                            if(res.data.resp_code == 999999){
                            	alert(res.data.resp_message);
                            }
								
                            },function (res) {
                            	console.log(res)
                                console.log("失败")

                            }
                        );
					},
				}
			})
			
		})
	</script>
</html>

